//
//  KWTVppRecordDataCell.m
//  RuiHeApp
//
//  Created by Yan Chen on 2024/10/17.
//

#import "KWTVppRecordDataCell.h"
#import "KWTVppSetResultModel.h"
#import "KWTMGRNSettingModel.h"
#import "KWT233KSettingModel.h"
#import "RHSolarkSettingModel.h"
#import "RHVppSetCommonModel.h"

@interface KWTVppRecordDataCell()


@end
@implementation KWTVppRecordDataCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}

//下发结果
-(void)setResultModel:(KWTVppSetResultModel *)resultModel
{
    _resultModel = resultModel;
    QMUILabel *plantNameLab = [self.contentView viewWithTag:100];
    plantNameLab.text = resultModel.plantName;
    
    QMUILabel *successLab = [self.contentView viewWithTag:102];
    successLab.text = [NSString stringWithFormat:@"%ld",resultModel.successNum];
    
    QMUILabel *failLab = [self.contentView viewWithTag:103];
    failLab.text = [NSString stringWithFormat:@"%ld",resultModel.failureNum];
    
    QMUILabel *stateLab = [self.contentView viewWithTag:101];
    switch (resultModel.status) {// 状态  0:下发中 1:成功 2:部分成功 3: 失败
        case 0:
            stateLab.text = @"下发中".rh_localized;
            break;
        case 1:
            stateLab.text = @"成功".rh_localized;
            break;
        case 2:
            stateLab.text = @"部分成功".rh_localized;
            break;
        case 3:
            stateLab.text = @"失败".rh_localized;
            break;
        default:
            stateLab.text = @"--";
            break;
    }
}

//下发策略
-(void)setParaS40KModel:(KWTMGRNSettingModel *)paraS40KModel
{
    _paraS40KModel = paraS40KModel;
    QMUILabel *timeLab = [self.contentView viewWithTag:100];
    KWTMGRNSettingModel *startTimeModel = [paraS40KModel.items safeObjectAtIndex:0];
    KWTMGRNSettingModel *endTimeModel = [paraS40KModel.items safeObjectAtIndex:1];
    NSString *startTime = ValidNullDataToString(startTimeModel.content, @"00:00");
    NSString *endTime = ValidNullDataToString(endTimeModel.content, @"00:00");
    timeLab.text = [NSString stringWithFormat:@"%@-%@",startTime,endTime];
    
    KWTMGRNSettingModel *stateModel = [paraS40KModel.items safeObjectAtIndex:2];
    QMUILabel *stateLab = [self.contentView viewWithTag:101];
    stateLab.text = stateModel.enumText.rh_localized;
    
    QMUILabel *socLab = [self.contentView viewWithTag:102];
    KWTMGRNSettingModel *socModel = [paraS40KModel.items safeObjectAtIndex:3];
    socLab.text = ValidNullDataToString(socModel.content, @"0");
    
    QMUILabel *powerLab = [self.contentView viewWithTag:103];
    KWTMGRNSettingModel *powerModel = [paraS40KModel.items safeObjectAtIndex:4];
    powerLab.text = ValidNullDataToString(powerModel.content, @"0");
    
}

//下发策略
- (void)setPara233Model:(KWT233KSettingModel *)para233Model
{
    _para233Model = para233Model;
    QMUILabel *timeLab = [self.contentView viewWithTag:100];
  
    timeLab.text = para233Model.comment;
    
    QMUILabel *socLab = [self.contentView viewWithTag:102];
    KWTMGRNSettingModel *socModel = [para233Model.items safeObjectAtIndex:1];
    socLab.text = ValidNullDataToString(socModel.content, @"0");
    
    QMUILabel *powerLab = [self.contentView viewWithTag:103];
    KWTMGRNSettingModel *powerModel = [para233Model.items safeObjectAtIndex:2];
    powerLab.text = ValidNullDataToString(powerModel.content, @"0");
    
    KWTMGRNSettingModel *stateModel = [para233Model.items safeObjectAtIndex:0];
    QMUILabel *stateLab = [self.contentView viewWithTag:101];
    if ([powerModel.content doubleValue]>0) {
        stateLab.text = @"充电".rh_localized;
    }else if ([powerModel.content doubleValue]<0) {
        stateLab.text = @"放电".rh_localized;
    }else{
        stateLab.text = @"--";
    }
}

//61度电
-(void)setPara61Model:(RHSolarkSettingModel *)para61Model
{
    _para61Model = para61Model;
  
    QMUILabel *timeLab = [self.contentView viewWithTag:100];
    RHSolarkSettingModel *startTimeModel = [para61Model.items safeObjectAtIndex:1];
    RHSolarkSettingModel *endTimeModel = [para61Model.items safeObjectAtIndex:2];
    NSString *startTime = ValidNullDataToString(startTimeModel.content, @"00:00");
    NSString *endTime = ValidNullDataToString(endTimeModel.content, @"00:00");
    timeLab.text = [NSString stringWithFormat:@"%@-%@",startTime,endTime];
    
    //充放电状态
    RHSolarkSettingModel *stateModel = [para61Model.items safeObjectAtIndex:0];
    QMUILabel *stateLab = [self.contentView viewWithTag:101];
    stateLab.text = stateModel.enumText.rh_localized;
    
    QMUILabel *socLab = [self.contentView viewWithTag:102];
    RHSolarkSettingModel *socModel = [para61Model.items safeObjectAtIndex:3];
    socLab.text = ValidNullDataToString(socModel.content, @"0");
    
    QMUILabel *powerLab = [self.contentView viewWithTag:103];
    RHSolarkSettingModel *powerModel = [para61Model.items safeObjectAtIndex:4];
    powerLab.text = ValidNullDataToString(powerModel.content, @"0");
}

//储充一体
-(void)setParaHiSolarkModel:(RHVppSetCommonModel *)paraHiSolarkModel
{
    _paraHiSolarkModel = paraHiSolarkModel;
  
    QMUILabel *timeLab = [self.contentView viewWithTag:100];
    RHVppSetCommonModel *startTimeModel = [paraHiSolarkModel.items safeObjectAtIndex:0];
    RHVppSetCommonModel *endTimeModel = [paraHiSolarkModel.items safeObjectAtIndex:1];
    NSString *startTime = ValidNullDataToString(startTimeModel.content, @"00:00");
    NSString *endTime = ValidNullDataToString(endTimeModel.content, @"00:00");
    timeLab.text = [NSString stringWithFormat:@"%@-%@",startTime,endTime];
    
    //充放电状态
    RHVppSetCommonModel *stateModel = [paraHiSolarkModel.items safeObjectAtIndex:2];
    QMUILabel *stateLab = [self.contentView viewWithTag:101];
    stateLab.text = stateModel.enumText.rh_localized;
    
    QMUILabel *socLab = [self.contentView viewWithTag:102];
    RHVppSetCommonModel *socModel = [paraHiSolarkModel.items safeObjectAtIndex:3];
    socLab.text = ValidNullDataToString(socModel.content, @"0");
    
    QMUILabel *powerLab = [self.contentView viewWithTag:103];
    RHVppSetCommonModel *powerModel = [paraHiSolarkModel.items safeObjectAtIndex:4];
    powerLab.text = ValidNullDataToString(powerModel.content, @"0");
}


- (void)setupUI{
    kWeakSelf;
    [self setBackgroundColor:UIColor.clearColor];
    [self.contentView setBackgroundColor:CFTabViewBgColor];
    
    
    UIView *bgView = [[UIView alloc] init];
    [bgView setBackgroundColor:UIColor.whiteColor];
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
        make.height.offset(35);
    }];
    CGFloat labWidth = (kUI_WINDOW_W - 30 -20)/4;
    for (int i = 0; i<4; i++) {
        QMUILabel *lab = [QMUILabel labelWithText:@"--" font:kSYSTEMFONT(13) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
        lab.adjustsFontSizeToFitWidth = YES;
        lab.minimumScaleFactor = 0.8;
        lab.textAlignment = NSTextAlignmentCenter;
        lab.tag = 100 + i;
        lab.numberOfLines = 2;
        [bgView addSubview:lab];
        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(i*labWidth+10);
            make.centerY.mas_offset(0);
            make.width.offset(labWidth);
        }];
    }
    
    
}
@end
